@extends('layouts.console_header')

@section('title', '地推待提现')

@section('resources')
    @parent
    <style>
        .prompt_double{width: 500px;position: fixed;top: 200px;left: 50%;margin-left: -250px;background-color: #fff;z-index: 1001;box-shadow: 0px 0px 5px 5px rgba(128,128,128,0.5);}
        .prompt_double .title{font-size: 24px;color: #343434;margin-top: 30px;text-align: center;}
        .prompt_double .content{color: #343434;margin-top: 30px;overflow: hidden;}
        .prompt_double .remark{color: #343434;margin-top: 30px;overflow: hidden;display: none;}
        .prompt_double .prompt{color: red;display: none;text-align: center;font-size: 16px;}
        .prompt_double .content span{float: left;margin-left: 70px;font-size: 16px;width: 80px;text-align: right;margin-right: 20px;}
        .prompt_double .remark span{float: left;margin-left: 70px;font-size: 16px;width: 80px;text-align: right;margin-right: 20px;}
        .prompt_double .content select{float: left;border: 1px solid #000;font-size: 14px;}
        .prompt_double .remark textarea{float: left;border: 1px solid #000;font-size: 14px;width: 250px;height: 70px;padding: 10px;}
        .prompt_double .close_pic{width: 30px;height: 30px;position: absolute;top: 10px;right: 10px;}
        .prompt_double .button{margin-top: 30px;font-size: 24px;}
        .prompt_double .button span{width: 100px;height: 40px;text-align: center;line-height: 40px;border-radius: 5px;cursor: pointer;}
        .prompt_double .button .cancel{margin: 10px 0 30px 20px;background-color: #eee;}
        .prompt_double .button .sure{margin: 10px 20px 30px 0;}
        .prompt_success{width: 100px;position: fixed;top: 250px;left: 50%;margin-left: -60px;background: rgba(0,0,0,0.5);padding: 10px;z-index: 1002;text-align: center;color: #fff;display: none;}
        .salesman_type{background-color: #fff;overflow: hidden;}
        .salesman_type span{padding: 10px 30px;margin: 20px 10px 0 10px;float: left;cursor: pointer;}
        .salesman_type_show{border-bottom: 3px solid #9955c6;color: #9955c6;}
    </style>
@endsection

@section('content')
<section class="user_list">
	<div style="border-bottom: 2px solid #9955c6;overflow: hidden;">
		<p class="fz_14 account_title fl" style="border: none;">
		    <span style="color: #7f7f7f;"><a href="/console/index">首页</a>>财务中心></span>
		    <span class="co_violet">地推待提现</span>
		</p>
		<a href="#" onclick="export_data()"><p class="fr tc back_btn">导出</p></a>
	</div>
    <p class="salesman_type">
        <span><a href="/console/finance/salesman/waitwithdrawal/index?cityid={{$cityid}}&salesmantype=shopsalesman">商家地推</a></span>
        <span><a href="/console/finance/salesman/waitwithdrawal/index?cityid={{$cityid}}&salesmantype=usersalesman">个人地推</a></span>
    </p>
    @if($salesmantype == 'shopsalesman')
        <div class="salesman_shop">
        <table class="finance_top_list">
            <tr>
                <th>待提现笔数</th>
                <th>待提现金额(元)</th>
            </tr>
            <tr>
                <td>{{$statistic['shopnum']}}</td>
                <td>{{$statistic['waitwithdrawalmoney']}}</td>
            </tr>
        </table>
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>商家代码</th>
                    <th>商家名称</th>
                    <th>持卡人</th>
                    <th>银行卡号</th>
                    <th>银行名称</th>
                    <th>开户行所在地</th>
                    <th>开户行名称</th>
                    <th>待提现金额(元)</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>序号</th>
                    <th>商家代码</th>
                    <th>商家名称</th>
                    <th>持卡人</th>
                    <th>银行卡号</th>
                    <th>银行名称</th>
                    <th>开户行所在地</th>
                    <th>开户行名称</th>
                    <th>待提现金额(元)</th>
                    <th>操作</th>
                </tr>
            </tfoot>
            <tbody>
            @foreach($lists as $list)
                <tr>
                @if(!isset($i))
                    <td>{{$i=1}}</td>
                @else
                    <td>{{++$i}}</td>
                @endif
                    <td>{{$list['shopcode']}}</td>
                    <td>{{$list['shopname']}}</td>
                    <td>{{$list['cardholder']}}</td>
                    <td>{{$list['bankcard']}}</td>
                    <td>{{$list['bankname']}}</td>
                    <td>{{$list['bankprovince']}}{{$list['bankcity']}}</td>
                    <td>{{$list['opencardbank']}}</td>
                    <td>{{$list['accountamount']}}</td>
                    <td><a href="#" onclick="remit_salesman_shop('{{$list['withdrawalid']}}')">打款</a></td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
    @else
        <div class="salesman_user">
        <table class="finance_top_list">
            <tr>
                <th>待提现的地推(数)</th>
                <th>待提现金额(元)</th>
            </tr>
            <tr>
                <td>{{$statistic['usercount']}}</td>
                <td>{{$statistic['waitwithdrawalmoney']}}</td>
            </tr>
        </table>
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>个人地推账号</th>
                    <th>姓名</th>
                    <th>待提现金额</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>序号</th>
                    <th>个人地推账号</th>
                    <th>姓名</th>
                    <th>待提现金额</th>
                    <th>操作</th>
                </tr>
            </tfoot>
            <tbody>
            @foreach($lists as $list)
                <tr>
                @if(!isset($i))
                    <td>{{$i=1}}</td>
                @else
                    <td>{{++$i}}</td>
                @endif
                    <td>{{$list['mobile']}}</td>
                    <td>{{$list['name']}}</td>
                    <td>{{$list['accountmoney']}}</td>
                    <td><a class="co_violet" href="#" onclick="remit_salesman_user('{{$list['withdrawalid']}}')">打款</a></td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
    @endif
    <p class="prompt_success"></p>
</section>
@endsection

@section('scriptResources')
    @parent
    <script>
    var cityid='{{$cityid}}';
    var salesmantype = '{{$salesmantype}}';
    //给商家打款
    var promptDouble = $('<div class="prompt_double">'+
                            '<img class="fr close_pic" src="{{env('IMAGE_DOMAIN')}}images/close_p.png" alt="">'+
                            '<p class="title">确定要打款？</p>'+
                            '<p class="content">'+
                                '<span>打款状态:</span>'+
                                '<select name="" id="" onchange="drawal_state()">'+
                                    '<option value="0">正常打款</option>'+
                                    '<option value="1">异常打款</option>'+
                                '</select>'+
                            '</p>'+
                            '<p class="remark">'+
                                '<span>备注:</span>'+
                                '<textarea name="" id="" cols="30" rows="10" placeholder="必填,请输入实际打款金额与异常原因"></textarea>'+
                            '</p>'+
                            '<p class="prompt">备注不能为空</p>'+
                            '<p class="button oh">'+
                                '<span class="fl cancel">取消</span>'+
                                '<span class="fr sure">确定</span>'+
                            '</p>'+
                        '</div>');
    //给商家地推打款
    function drawal_state(){
        if($('.content select').val() == 0){
            $('.remark').hide();
        }else{
            $('.remark').show();
        }
    }
    function remit_salesman_shop(withdrawalid) {
        $(".public_prompt_mark").show();
        $(".public_prompt_mark").height($(window).height());
        $('body').append(promptDouble);
        $(".prompt_double .sure").click(function(){
            var remark = $('.remark textarea').val();
            if($('.content select').val() == 0){
                $.ajax({
                    "url":"/console/finance/salesman/shop/remit",
                    "dataType":"json",
                    "data":{
                        "withdrawalid":withdrawalid,
                        "cityid":cityid,
                        "remark":remark,
                        },
                    "type":"post",
                    "async":"true",
                    "success":function(data) {
                        $(".public_prompt_mark").show();
                        $(".prompt_success").show();
                        $(".prompt_success").html(data.message);
                        window.location.reload();
                    },
                    "error":function(data) {
                        $(".prompt_success").show();
                        $(".prompt_success").html(data.message);
                    }
                });
            }else{
                if(remark == ""){
                    $(".prompt_double .prompt").show();
                    $(".prompt_double .prompt").html("请填入备注");
                    return false;
                }else{
                    $.ajax({
                    "url":"/console/finance/salesman/shop/remit",
                    "dataType":"json",
                    "data":{
                        "withdrawalid":withdrawalid,
                        "cityid":cityid,
                        "remark":remark,
                        },
                    "type":"post",
                    "async":"true",
                    "success":function(data) {
                        $(".public_prompt_mark").show();
                        $(".prompt_success").show();
                        $(".prompt_success").html(data.message);
                        window.location.reload();
                    },
                    "error":function(data) {
                        $(".prompt_success").show();
                        $(".prompt_success").html(data.message);
                    }
                });
                }
            }
        });
        $(".prompt_double .cancel").click(function(){
            $(".public_prompt_mark").hide();
            $(".prompt_double").remove();
        });
        $(".prompt_double .close_pic").click(function(){
            $(".public_prompt_mark").hide();
            $(".prompt_double").remove();
        });
    }
    //给用户地推打款
    function remit_salesman_user(withdrawalid) {
        $(".public_prompt_mark").show();
        $(".public_prompt_mark").height($(window).height());
        $('body').append(promptDouble);
        $(".prompt_double .sure").click(function(){
            $.ajax({
                "url":"/console/finance/salesman/user/remit",
                "dataType":"json",
                "data":{
                    "withdrawalid":withdrawalid,
                    "cityid":cityid
                    },
                "type":"post",
                "async":"true",
                "success":function(data) {
                    $(".public_prompt_mark").show();
                    $(".prompt_success").show();
                    $(".prompt_success").html(data.message);
                    window.location.reload();
                },
                "error":function(data) {
                    $(".prompt_success").show();
                    $(".prompt_success").html(data.message);
                }
            });
        });
        $(".prompt_double .cancel").click(function(){
            $(".public_prompt_mark").hide();
            $(".prompt_double").remove();
        });
        $(".prompt_double .close_pic").click(function(){
            $(".public_prompt_mark").hide();
            $(".prompt_double").remove();
        });
    }
    if(salesmantype == 'usersalesman'){
        $(".salesman_type span").eq(1).addClass("salesman_type_show");
    }else{
        $(".salesman_type span").eq(0).addClass("salesman_type_show");
    }
    //导出功能
    function export_data() {
        window.open("/console/finance/salesman/waitwithdrawal/export?cityid="+cityid+"&salesmantype="+salesmantype, '_blank');
    }
    </script>
@endsection